package com.chenshanji.lease.common.utils;

import java.util.Random;

public class AvatarUtil {

    private static final Random RANDOM = new Random();

    private static final String[] TOP_TYPES = {
        "NoHair", "Eyepatch", "Hat", "Hijab", "Turban",
        "WinterHat1", "WinterHat2", "WinterHat3", "WinterHat4",
        "LongHairBigHair", "LongHairBob", "LongHairBun", "LongHairCurly",
        "ShortHairShortCurly", "ShortHairDreads01", "ShortHairDreads02",
        "ShortHairFrizzle", "ShortHairShaggyMullet"
    };

    private static final String[] ACCESSORIES_TYPES = {
        "Blank", "Kurt", "Prescription01", "Prescription02", "Round", "Sunglasses", "Wayfarers"
    };

    private static final String[] HAIR_COLORS = {
        "Auburn", "Black", "Blonde", "BlondeGolden", "Brown", "BrownDark",
        "PastelPink", "Platinum", "Red", "SilverGray"
    };

    private static final String[] FACIAL_HAIR_TYPES = {
        "Blank", "BeardMedium", "BeardLight", "BeardMagestic", "MoustacheFancy", "MoustacheMagnum"
    };

    private static final String[] CLOTHE_TYPES = {
        "BlazerShirt", "BlazerSweater", "CollarSweater", "GraphicShirt",
        "Hoodie", "Overall", "ShirtCrewNeck", "ShirtScoopNeck", "ShirtVNeck"
    };

    private static final String[] EYE_TYPES = {
        "Close", "Cry", "Default", "Dizzy", "EyeRoll",
        "Happy", "Hearts", "Side", "Squint", "Surprised", "Wink", "WinkWacky"
    };

    private static final String[] MOUTH_TYPES = {
        "Concerned", "Default", "Disbelief", "Eating", "Grimace",
        "Sad", "ScreamOpen", "Serious", "Smile", "Tongue", "Twinkle", "Vomit"
    };

    private static final String[] SKIN_COLORS = {
        "Tanned", "Yellow", "Pale", "Light", "Brown", "DarkBrown", "Black"
    };

    private static String getRandomElement(String[] array) {
        return array[RANDOM.nextInt(array.length)];
    }

    public static String generateRandomAvatarUrl() {
        return "https://avataaars.io/?" +
                "avatarStyle=Circle" +
                "&topType=" + getRandomElement(TOP_TYPES) +
                "&accessoriesType=" + getRandomElement(ACCESSORIES_TYPES) +
                "&hairColor=" + getRandomElement(HAIR_COLORS) +
                "&facialHairType=" + getRandomElement(FACIAL_HAIR_TYPES) +
                "&clotheType=" + getRandomElement(CLOTHE_TYPES) +
                "&eyeType=" + getRandomElement(EYE_TYPES) +
                "&mouthType=" + getRandomElement(MOUTH_TYPES) +
                "&skinColor=" + getRandomElement(SKIN_COLORS);
    }
}
